package com.app.security.satoken;

import cn.dev33.satoken.strategy.SaStrategy;
import cn.hutool.core.convert.Convert;
import com.app.core.security.TokenStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author qiangt
 * @version 1.0
 * @date 2023/10/16 15:29
 * @description: sa token 配置类
 */
@ComponentScan("com.app.security.satoken")
@Configuration
public class SaTokenAutoConfiguration {

    /**
     * 重写 Sa-Token 框架内部算法策略
     */
    @Autowired
    public void rewriteSaStrategy() {
        // 重写 Token 生成策略
        SaStrategy.instance.createToken = (loginId, loginType) -> {
            return TokenStrategy.generateToken(Convert.toStr(loginId));
        };
    }
}

